package de.umr.fb12.vs.os;

class OpCodes {
	/*
	 * op code format +--+--+--+--+----------+ |AC|T0|T1|T2|OP........|
	 * +--+--+--+--+----------+
	 * 
	 * AC = Argument Count, 2 bytes number of arguments AC + 1 = Instruction
	 * Length T0 = Type of Argument 0, 2 bytes, see argument types T1 = Type of
	 * Argument 0, 2 bytes, see argument types T2 = Type of Argument 0, 2 bytes,
	 * see argument types OP = actual operation code, 24 bytes
	 * 
	 * argument types -------------- 0/00 = value 1/01 = register 2/10 = memory
	 * 3/11 = reserved
	 */

	// constants for building OpCodes
	// -- argument count
	final static int ARGC_0 = 0;
	final static int ARGC_1 = 1 << 30;
	final static int ARGC_2 = 2 << 30;
	final static int ARGC_3 = 3 << 30;

	// -- argument types (non-shifted)
	final static int ARGT_VAL = 0;
	final static int ARGT_REG = 1;
	final static int ARGT_MEM = 2;

	// -- argument types (shifted)
	final static int ARGT0_VAL = ARGT_VAL << 28;
	final static int ARGT0_REG = ARGT_REG << 28;
	final static int ARGT0_MEM = ARGT_MEM << 28;
	final static int ARGT1_VAL = ARGT_VAL << 26;
	final static int ARGT1_REG = ARGT_REG << 26;
	final static int ARGT1_MEM = ARGT_MEM << 26;
	final static int ARGT2_VAL = ARGT_VAL << 24;
	final static int ARGT2_REG = ARGT_REG << 24;
	final static int ARGT2_MEM = ARGT_MEM << 24;

	// -- argument number and offset
	final static int ARG0 = 0;
	final static int ARG1 = 1;
	final static int ARG2 = 2;

	// halt
	final static int HLT = 0;

	// interrupt
	// INT ID(v)
	final static int INT = 1;

	// special operation
	// SOP ID(v)
	final static int SOP = 2;

	// unconditional jump
	// JMP ADDR(m)
	final static int JMP = 100;

	// conditional jumps
	// J<OP> VAL1(rm) VAL2(vrm) ADDR(m)
	final static int JLT = 101;
	final static int JLE = 102;
	final static int JEQ = 103;
	final static int JNE = 104;
	final static int JGT = 105;
	final static int JGE = 106;

	// move operation
	// MOV DST(rm) VAL(vrm) => DST
	final static int MOV = 10;

	// calculations
	// OP DST(rm) VAL(vrm) => DST
	final static int ADD = 20;
	final static int SUB = 21;
	final static int MUL = 22;
	final static int DIV = 23;
	final static int MOD = 24;

	// bitwise operations
	// OP DST(rm) => DST
	final static int NOT = 30;
	// OP DST(rm), VAL(vrm) => DST
	final static int AND = 31;
	final static int OR = 32;
	final static int XOR = 33;
	final static int SHR = 34;
	final static int SHL = 35;
}
